package com.qj.yantaishan.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.qj.yantaishan.vo.FtOrderVo;
import com.qj.yantaishan.vo.OrderProductVo;
import com.qj.yantaishan.vo.OrderVo;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface OrderVoMapper extends BaseMapper<OrderVo> {

    @Select("select op.pigcms_id,op.pro_num, op.pro_price,op.pro_weight,sp.name product_name," +
            "op.in_package_status,sp.image proPic from shanglala_order_product op inner join shanglala_product  sp on op.product_id = sp.product_id  where order_id =#{orderId}")
    List<OrderProductVo> selectOrderProductListByOrderId(Integer orderId);

    @Select("select so.order_no,custom_name,add_time,custom_tel,ft_year,ft_type,ft_name,so.total_metering,\n" +
            "ft_note,ft_anniversary,ft_bdname,ft_bdcard,ft_paytype,sop.sku_data,sowi.cert_path,sowi.video_path\n" +
            " from shanglala_order so left join shanglala_order_wine_info sowi \n" +
            "on so.order_id= sowi.order_id inner join shanglala_order_product sop on sop.order_id\n" +
            "= so.order_id where so.ft_paytype !=0 limit #{currentPage},#{pageSize} ")
    List<FtOrderVo> selectFtOrderPage(@Param("currentPage") Integer currentPage, @Param("pageSize") Integer pageSize);

    @Select("select count(*)" +
            " from shanglala_order so left join shanglala_order_wine_info sowi on so.order_id= sowi.order_id inner join shanglala_order_product sop on sop.order_id\n" +
            "= so.order_id where so.ft_paytype !=0 ")
    Integer ftOrderTotal();

    @Select("select so.order_no,custom_name,add_time,custom_tel,ft_year,ft_type,ft_name,so.total_metering,\n" +
            "ft_note,ft_anniversary,ft_bdname,ft_bdcard,ft_paytype,sop.sku_data,sowi.cert_path,sowi.video_path\n" +
            " from shanglala_order so left join shanglala_order_wine_info sowi \n" +
            "on so.order_id= sowi.order_id inner join shanglala_order_product sop on sop.order_id\n" +
            "= so.order_id where so.ft_paytype !=0 and order_id =#{orderId} ")
    FtOrderVo getFtOrderDetail(Integer orderId);

    @Update("<script>update shanglala_order_wine_info set" + " <if test='certPath!=null'> cert_path=#{certPath},</if>"
            + "<if test = 'videoPath!=null' > video_path=#{videoPath}</if>" + " where order_id = #{orderId} </script>")
    int saveFtOrder(@Param("certPath") String certPath, @Param("videoPath") String videoPath, @Param("orderId") String orderId);

    @Select("select count(*) from shanglala_order_wine_info where order_id=#{orderId}")
    int getFtOrderWine(Integer orderId);

    @Insert("insert into shanglala_order_wine_info(order_id,cert_path,video_path) values(#{orderId},#{certPath},#{videoPath})")
    int insertFtOrderDetail(@Param("certPath") String certPath, @Param("videoPath") String videoPath, @Param("orderId") String orderId);

    /**
     * 待发货訂單數
     *
     * @return
     * @Excel(name = "订单状态 0临时订单 1未支付 2未发货 3已发货 4已完成 5已取消 6退款中 ")
     * private Integer status;
     */
    @Select("select count(*) from shanglala_order where status= 2")
    int getNoShipNumber();

    /**
     * 近七天订单数
     * @param nowTime
     * @param before7Time
     * @return
     */
    @Select("select count(*) from shanglala_order where add_time < #{nowTime} and add_time>#{before7Time}")
    int get7DayOrderNumber(@Param("nowTime") Long nowTime, @Param("before7Time") Long before7Time);
    @Select("select count(*) from shanglala_order where status= 1")
    int getNoPayOrderNum();
    @Select("select count(*) from shanglala_order where status= 3")
    int getShopNumber();
    @Select("select sum(pay_money) from shanglala_order where status!=1 and add_time < #{nowTime} and add_time>#{before7Time}")
    Double getOrder7DayPayMoney(@Param("nowTime") Long nowTime, @Param("before7Time") Long before7Time);
    @Select("select sum(sale_total) from shanglala_order where status!=1 and store_id =1")
    Double getOrderTotalMoney();
    @Select("select count(*) from shanglala_order where add_time < #{endTime} and add_time>#{startTime} and status =3")
    int getNowDayShip(@Param("startTime") long startTime,@Param("endTime") long endTime);
    @Select("select count(*) from shanglala_order where add_time < #{endTime} and add_time>#{startTime} and status !=1 and status!=0")
    int getNowDayPay(@Param("startTime") long startTime,@Param("endTime") long endTime);
    @Select("select count(*) from shanglala_order where add_time < #{endTime} and add_time>#{startTime}")
    int getNowDayOrder(@Param("startTime") long startTime,@Param("endTime") long endTime);
}
